package test.com.googlecode.pdfbricks.engine.util;

import java.io.File;
import java.io.IOException;

public class PdfFileRenameUtils {

	public static File renameExistFile(final String filePath) throws IOException{
		int i=1;
		String newFilePath=filePath;
		File file=new File(newFilePath);
		String originalFileName=file.getName();
		String newFileName=null;
		while(file.exists()){
			newFileName=originalFileName.replaceFirst("\\.pdf", "("+String.valueOf(i)+")"+".pdf");
			newFilePath=file.getParent()+File.separator+newFileName;
			file=new File(newFilePath);
			i++;
		}
		if(!filePath.equals(newFilePath)){
		    System.out.println("rename "+filePath+" to "+newFilePath);
		}
		return file;
	}
}
